<!DOCTYPE html>
<html>
<head>
    <title>备件清单</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div >
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="4">
                    <i-input v-model="q.materCode" @on-enter="query" placeholder="领料单号"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.partName" @on-enter="query" placeholder="备件名称"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.spec" @on-enter="query" placeholder="规格"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.partCode" @on-enter="query" placeholder="备件编码"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.erpCode" @on-enter="query" placeholder="ERP编码"></i-input>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>
<script>
    function getUrlParam(paramName) {
        var searchParams = new URLSearchParams(window.location.search);
        return searchParams.get(paramName);
    }
    // 只获取可以更换关联的
    $(function () {
        var materialType = getUrlParam('materialType');
        var url = `../materialrecord/list?delFlag=1&isReplaceable=1&materialType=${materialType}`;
        $("#jqGrid").Grid({
            url: url,
            colModel: [
                {label: '领料单号', name: 'material', align: 'center', index: 'MB.MATER_CODE', width: 120},
                {
                    label: '领料类别', align: 'center', width: 80, index: 'MB.MATERIAL_TYPE',
                    formatter: function (value, col, row) {
                        return row.materialType?sysEnums.MATER_TYPE[row.materialType]:'线边库';
                    }
                },
                {label: '领用部门', name: 'deptName', align: 'center', index: 'DEPT_NAME', width: 80},
                {label: '申请人', name: 'pickerName', align: 'center', index: 'PICKER_NAME', width: 50},
                {
                    label: '申请时间', name: 'pickDate', align: 'center', index: 'PICK_DATE',  width: 110,
                    formatter: function (value) {
                        return transDate(value, 'yyyy-MM-dd hh:mm');
                    }
                },
                {label: '用途', name: 'purpose', align: 'center', index: 'PURPOSE', width: 80},
                {label: '备件编码', name: 'spareCode', align: 'center', index: 'SPARE_CODE', width: 80},
                {label: '备件名称', name: 'spareName', align: 'center', index: 'SPARE_NAME', width: 80},
                {label: '规格', name: 'spec', align: 'center', index: 'SPEC', width: 110},
                {label: '仓库名称', name: 'storeName', align: 'center', index: 'STORE_NAME', width: 200},
                {label: '备件位置', name: 'postion', align: 'center', index: 'POSTION', width:120},
                {label: '领用数', name: 'actualNum', align: 'center', index: 'ACTUAL_NUM', width: 50},
                {label: '更换数', name: 'replaceNum', align: 'center', index: 'TRPLACE_NUM', width: 50},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ],
            sortname:'PICK_DATE',
            sortorder:'desc',
        });
    });

    let vm = new Vue({
        el: '#rrapp',
        data: {
            materialType:'',
            q: {
                materCode: '',
                partName: '',
                spec:'',
                partCode: '',
                erpCode:''
            }
        },
        methods: {

            query: function () {
                vm.reload();
            },
            reload: function (event) {
                // 清楚postData缓存
                var postData = $("#jqGrid").jqGrid("getGridParam", "postData");
                $.each(postData, function (k, v) {
                    delete postData[k];
                });
                let page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    search: true,
                    postData:vm.q,
                    page: page
                }).trigger("reloadGrid",[{page: 1}]);
            },
            reloadSearch: function () {
                vm.q = {
                    materCode: '',
                    partName: '',
                    spec:'',
                    partCode: '',
                    erpCode:''
                };
                vm.reload();
            },
            handleSubmit: function (name) {
                handleSubmitValidate(this, name, function () {
                    vm.saveOrUpdate()
                });
            },
            handleReset: function (name) {
                handleResetForm(this, name);
            }
        }
    });
    // 获取选中备件列表
    var getSparePart = function () {
        return getSelectedRowData("#jqGrid");
    }
    // 获取所有已选备件ID列表
    var getSelectedSpareParts = function () {
        return getSelectedRows("#jqGrid");
    }
</script>

</body>
</html>
